package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JLayeredPane;

import br.com.fafica.sisape.control.ControllerUsuario;

import java.awt.ScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaUsuario extends JFrame {

	private JPanel contentPane;
	private JTextField txtUsuario;
	private JPasswordField txtSenha;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaUsuario frame = new TelaUsuario();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaUsuario() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 270, 410);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("arquivos\\TelaUsuario.png"));
		label.setBounds(0, 0, 264, 139);
		contentPane.add(label);
		
		JPanel panelLogin = new JPanel();
		panelLogin.setBackground(Color.WHITE);
		panelLogin.setBounds(0, 129, 264, 252);
		contentPane.add(panelLogin);
		panelLogin.setLayout(null);
		
		JLabel lblUsurio = new JLabel("Usu\u00E1rio:");
		lblUsurio.setHorizontalAlignment(SwingConstants.RIGHT);
		lblUsurio.setForeground(new Color(0, 0, 128));
		lblUsurio.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		lblUsurio.setBounds(51, 67, 46, 17);
		panelLogin.add(lblUsurio);
		
		txtUsuario = new JTextField();
		txtUsuario.setForeground(new Color(0, 0, 128));
		txtUsuario.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		txtUsuario.setBounds(99, 65, 116, 23);
		panelLogin.add(txtUsuario);
		txtUsuario.setColumns(10);
		
		JLabel lblSenha = new JLabel("Senha:");
		lblSenha.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSenha.setForeground(new Color(0, 0, 128));
		lblSenha.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		lblSenha.setBounds(51, 94, 46, 17);
		panelLogin.add(lblSenha);
		
		txtSenha = new JPasswordField();
		txtSenha.setForeground(new Color(0, 0, 128));
		txtSenha.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		txtSenha.setBounds(99, 92, 116, 23);
		panelLogin.add(txtSenha);
		
		JButton btnEntrar = new JButton("Entrar");
		btnEntrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String login = txtUsuario.getText();
				String senha = txtSenha.getText();
				
				ControllerUsuario control = new ControllerUsuario();
				boolean userLogin = control.validarLogin(login, senha);
				
				if(userLogin == true){
					TelaUsuarioPrincipal telaPrincipal = new TelaUsuarioPrincipal();
					telaPrincipal.setLocation(0, 0);
					telaPrincipal.setVisible(true);
					dispose();
				}else{
					TelaMensagemLogin telaMen = new TelaMensagemLogin();
					telaMen.setVisible(true);
				}
			}
		});
		btnEntrar.setHorizontalTextPosition(SwingConstants.CENTER);
		btnEntrar.setForeground(new Color(0, 0, 128));
		btnEntrar.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		btnEntrar.setBounds(89, 136, 99, 25);
		panelLogin.add(btnEntrar);
		
		JButton btnCadastrese = new JButton("Cadastre-se");
		btnCadastrese.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaUsuarioCadastro telaCadas = new TelaUsuarioCadastro();
				telaCadas.setLocation(0, 0);
				telaCadas.setVisible(true);
			}
		});
		btnCadastrese.setHorizontalTextPosition(SwingConstants.CENTER);
		btnCadastrese.setForeground(new Color(0, 0, 128));
		btnCadastrese.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		btnCadastrese.setBounds(77, 172, 122, 25);
		panelLogin.add(btnCadastrese);
		
		JLabel lblTerminalUsurio = new JLabel("TERMINAL USU\u00C1RIO");
		lblTerminalUsurio.setForeground(new Color(0, 0, 128));
		lblTerminalUsurio.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblTerminalUsurio.setBounds(51, 11, 164, 31);
		panelLogin.add(lblTerminalUsurio);
	}
}
